var util = require('../../../utils/util')
var api = require('../../../config/api');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    task: {},
    //审批流程记录
    reportRecord: [],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    const eventChannel = this.getOpenerEventChannel()
    // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('row', function (data) {
      console.log(data)
      // that.setData({
      //   report: data,
      //   imgList: (data.fliePath || '').split(';').filter(item => item !== ''),
      //   imgListed: (data.verifyImage || '').split(';').filter(item => item !== '')
      // })
      //获取任务详情
      that.queryTaskDetail(data.taskId)
      
    })

  },

  
  /**
   *获取历史审批记录
   */
   queryTaskDetail(taskId) {
    let that = this
    var pageInfo = {
      taskId: taskId
    }
    that.loadModal();
    util.request(api.queryTaskDetail, JSON.stringify(pageInfo), 'POST').then(function (res) {
      console.log(res)
      if (res.code === "200") {
        that.closeModal();
        //刷新界面
        that.setData({
          task: res.data,
          imgList: (res.data.hiddenReport.fliePath || '').split(';').filter(item => item !== ''),
          imgListed: (res.data.hiddenReport.verifyImage || '').split(';').filter(item => item !== '')
        });
        //获取历史审批记录
      that.getRecord(res.data.reportId)
      } else {
        util.showErrorToast(res.message);
        that.closeModal();
      }

    }).catch((err) => {
      that.closeModal();
      console.log("登录远程服务器catch:" + err);
      //reject(err);
    });
  },

  /**
   *获取历史审批记录
   */
  getRecord(reportId) {
    let that = this
    var pageInfo = {
      reportId: reportId
    }
    that.loadModal();
    util.request(api.getReportRecord, JSON.stringify(pageInfo), 'POST').then(function (res) {
      console.log(res)
      if (res.code === "200") {
        that.closeModal();
        //刷新界面
        that.setData({
          reportRecord: res.data,
        });
      } else {
        util.showErrorToast(res.message);
        that.closeModal();
      }

    }).catch((err) => {
      that.closeModal();
      console.log("登录远程服务器catch:" + err);
      //reject(err);
    });
  },


  //浏览图片
  ViewImage(e) {
    wx.previewImage({
      urls: this.data.imgList,
      current: e.currentTarget.dataset.url
    });
  },
  //浏览核实照片
  ViewImageed(e) {
    wx.previewImage({
      urls: this.data.imgListed,
      current: e.currentTarget.dataset.url
    });
  },

  //进度条
  loadModal() {
    this.setData({
      loadModal: true
    })
  },
  closeModal() {
    this.setData({
      loadModal: false
    })
  },



})